package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysRequestsField;
import com.ruoyi.system.service.ISysRequestsFieldService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 接口字段Controller
 * 
 * @author yql
 * @date 2023-09-19
 */
@RestController
@RequestMapping("/system/field")
public class SysRequestsFieldController extends BaseController
{
    @Autowired
    private ISysRequestsFieldService sysRequestsFieldService;

    /**
     * 查询接口字段列表
     */
    @PreAuthorize("@ss.hasPermi('system:field:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRequestsField sysRequestsField)
    {
        startPage();
        List<SysRequestsField> list = sysRequestsFieldService.selectSysRequestsFieldList(sysRequestsField);
        return getDataTable(list);
    }

    /**
     * 导出接口字段列表
     */
    @PreAuthorize("@ss.hasPermi('system:field:export')")
    @Log(title = "接口字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRequestsField sysRequestsField)
    {
        List<SysRequestsField> list = sysRequestsFieldService.selectSysRequestsFieldList(sysRequestsField);
        ExcelUtil<SysRequestsField> util = new ExcelUtil<SysRequestsField>(SysRequestsField.class);
        util.exportExcel(response, list, "接口字段数据");
    }

    /**
     * 获取接口字段详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:field:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysRequestsFieldService.selectSysRequestsFieldById(id));
    }

    /**
     * 新增接口字段
     */
    @PreAuthorize("@ss.hasPermi('system:field:add')")
    @Log(title = "接口字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRequestsField sysRequestsField)
    {
        return toAjax(sysRequestsFieldService.insertSysRequestsField(sysRequestsField));
    }

    /**
     * 修改接口字段
     */
    @PreAuthorize("@ss.hasPermi('system:field:edit')")
    @Log(title = "接口字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRequestsField sysRequestsField)
    {
        return toAjax(sysRequestsFieldService.updateSysRequestsField(sysRequestsField));
    }

    /**
     * 删除接口字段
     */
    @PreAuthorize("@ss.hasPermi('system:field:remove')")
    @Log(title = "接口字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysRequestsFieldService.deleteSysRequestsFieldByIds(ids));
    }
}
